package com.fsserver.config;

import com.fsserver.common.utils.OrderNoGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener;

/**
 * 订单号生成器配置类
 * 用于初始化订单号生成器
 * 
 * @author fsserver
 * @date 2025-03-13
 */
@Configuration
public class OrderNoGeneratorConfig {
    
    @Autowired
    private OrderNoConfig orderNoConfig;
    
    /**
     * 应用启动后初始化订单号生成器
     */
    @EventListener(ApplicationReadyEvent.class)
    public void initOrderNoGenerator() {
        // 初始化雪花算法ID生成器
        OrderNoGenerator.initSnowflake(
                orderNoConfig.getDataCenterId(),
                orderNoConfig.getWorkerId(),
                orderNoConfig.isEnableDistributed()
        );
    }
} 